package org.indi.yudidi;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

/**
 * Created by didi on 01/07/2018.
 */

/**
 * 自定义
 */
public class ReadResources {
    public static void main(String[] args) {
        useDefaultClassLoader();
        System.out.println(">>>>>>>>>>>>>>>");
        useSpecficClassLoader();
    }

    public static void useDefaultClassLoader(){
        String servicePath = "META-INF/services/";
        String interfaceFile ="java.sql.Driver";
        try {
            Enumeration<URL> configs = ClassLoader.getSystemResources(servicePath+interfaceFile);
            while (configs.hasMoreElements()){
                System.out.println(configs.nextElement());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void useSpecficClassLoader(){
        String servicePath = "META-INF/services/";
        String interfaceFile ="java.sql.Driver";
        try {
            ClassLoader ext = ReadResources.class.getClassLoader().getParent();
            Enumeration<URL> configs = ext.getResources(servicePath+interfaceFile);
            while (configs.hasMoreElements()){
                System.out.println(configs.nextElement());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
